<template>
  <div>
    <!-- 面包屑导航栏 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片试图区 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="orderConList.query" clearable @clear="getOderInfo" @keyup.enter.native="getOderInfo">
            <el-button slot="append" icon="el-icon-search" @click="getOderInfo"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 数据表格区 -->
      <el-table :data="ordersList" style="width: 100%" border stripe>
        <el-table-column type="index">
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="80px">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="80px">
          <template scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status==='1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="60px">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="180px">
          <template scope="scope">
            {{scope.row.create_time*1000|dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="240px">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="small" @click="changeAddress"></el-button>
            <el-button type="success" icon="el-icon-location" size="small" @click="logisticsInfo" disabled></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="orderConList.pagenum" :page-sizes="[10, 15, 20, 30]" :page-size="orderConList.pagesize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="addressdialogVisible" width="50%" @close="clearDialog">
      <el-form :model="addressruleForm" :rules="addressrules" ref="addressruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="地址信息" prop="addressOne">
          <!-- 级联选择器 -->
          <el-cascader v-model="addressruleForm.addressOne" :options="cityData" :props="{ expandTrigger: 'hover' }" @change="handleChange"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="addressTow">
          <el-input v-model="addressruleForm.addressTow"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressdialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看物流信息 -->
    <el-dialog title="物流信息" :visible.sync="logisticsdialogVisible" width="50%">
      <!-- 物流时间线 -->
      <el-timeline>
        <el-timeline-item v-for="(activity, index) in Wl.data" :key="index" :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
  import cityData from '../../assets/js/citydata.js'
  import Wl from '../../assets/js/Wl.js'
  export default {
    name: 'Order',
    data () {
      return {
        // 订单信息查询条件
        orderConList: {
          // 查询参数
          query: '',
          // 当前页码
          pagenum: 1,
          // 每页显示条数
          pagesize: 10
        },
        // 订单数据条数
        total: 0,
        // 订单信息
        ordersList: [],
        // 关闭修改地址的对话框
        addressdialogVisible: false,
        // 地址信息
        addressruleForm: {
          addressOne: '',
          addressTow: ''
        },
        addressrules: {
          addressOne: [{ required: true, message: '请输入地址', trigger: 'blur' },],
          addressTow: [{ required: true, message: '请输入详细地址', trigger: 'blur' },]
        },
        // 地址xinx
        cityData,
        Wl,
        // 物流信息
        WllogisticsList: {},
        // 关闭物流信息对话框
        logisticsdialogVisible: false
      }

    },
    created () {
      this.getOderInfo()
    },
    methods: {
      // 获取订单信息数据
      async getOderInfo () {
        const { data: res } = await this.$http.get(`orders`, { params: this.orderConList })
        // console.log(res);
        if (res.meta.status == !200) {
          return this.$message.error('获取订单信息失败')
        }
        this.ordersList = res.data.goods
        this.total = res.data.total
      },
      //监听每页显示条数 pageSize 改变时会触发事件
      handleSizeChange (newPage) {
        this.orderConList.pagesize = newPage
        this.getOderInfo()
      },
      // 监听页码值改变的事件
      handleCurrentChange (newSize) {
        this.orderConList.pagenum = newSize
        this.getOderInfo()
      },
      // 修改地址
      changeAddress () {
        this.addressdialogVisible = true
      },
      // 监听级联
      handleChange () {
      },
      // 监听修改地址对话框
      clearDialog () {
        this.$refs.addressruleForm.resetFields()
      },
      // 监听查看物流进度事件
      logisticsInfo () {
        this.logisticsdialogVisible = true
        console.log(this.Wl);
      }
    },
  }
</script>

<style lang="less" scoped>

</style>